#include "connection.hpp"

void callback(const zhong::Channel::ptr &channel, const std::string &consumer_tag, const zhong::BasicProperties *bp, const std::string &body)
{
    DEBUG_LOG("消费者[%s]接收到消息[%s]", consumer_tag.c_str(), body.c_str());
    channel->basicAck(bp->id());
}
int main()
{
    // 1.实例化异步工作线程对象
    zhong::AsyncWorker::ptr worker = std::make_shared<zhong::AsyncWorker>();
    // 2.实例化连接对象
    zhong::Connection::ptr connection = std::make_shared<zhong::Connection>("127.0.0.1", 8888, worker);
    // 3.通过链接创建并获取信道
    zhong::Channel::ptr channel = connection->openChannel();
    // 1.选择虚拟机
    channel->selectVirtualHost("host1");
  
    
    // 订阅了哪个队列？这里表示当前消费者consumer1订阅了这个queue2的消息
    auto func = std::bind(callback, channel, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
    channel->basicConsume("consumer1", "queue2", false, func);

    while (1)
    {
        std::this_thread::sleep_for(std::chrono::seconds(3));
    }
}